{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e03944d7",
   "metadata": {},
   "source": [
    "# 2022/9/13 python课堂笔记"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af047f41",
   "metadata": {},
   "source": [
    "#### 上周回顾(range())  range:范围"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "02fe36e3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "1a7877f8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# for+range:决定循环次数\n",
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0ad745c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "785fdca6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8fc5f3f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "50e5d07a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "003b95bf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "5\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b4ca4fc",
   "metadata": {},
   "source": [
    "### 课后练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7f9053a5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 10)"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "17d3e99f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(10):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "27ef400b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 12, 4)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,12,4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bea8782d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "5\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,12,4):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "6ee24353",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 10, 2)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(0,10,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c8b396f8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "2\n",
      "4\n",
      "6\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "for i in range(0,10,2):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "96c1d03f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 2, 3, 4, 5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(1,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad91e0b2",
   "metadata": {},
   "outputs": [],
   "source": [
    "# start:开头 开始  stop：停止  step：步\n",
    "range(start,stop,step)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a784fb1f",
   "metadata": {},
   "source": [
    "# 本周学习笔记\n",
    "* type():检查类型\n",
    "> 1. 数值 （用来运算）\n",
    ">> 1. int  整数\n",
    ">> 2. float 浮点数\n",
    ">> 3. complex  复数  虚数\n",
    "\n",
    "\n",
    "> 2. 字符串  （文本信息）\n",
    ">> 1. 字符串的定义  单引号  双引号 三引号\n",
    ">> 2. 字符串的拼接\n",
    ">>> 3. 字符串不可以和数字连接\n",
    ">>> 4. 字符串不可以用来运算\n",
    ">> 3. 字符串方法\n",
    ">>> 1. .capitalize(): 可以将字母转化为大写\n",
    ">>> 2. .count(): 数量  （）里面写要查找的内容\n",
    ">>> 3. .split()\n",
    ">> 4. in  检查成员对象\n",
    ">> 5. len() 检查文本总长度\n",
    ">> 6. enumerate:枚举，即可以获取内容，又可以获取索引值\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f02b592a",
   "metadata": {},
   "source": [
    "# Number(数值)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "562bb2d6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9\n"
     ]
    }
   ],
   "source": [
    "a = 9\n",
    "print(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f19a113b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# type() 查找类型\n",
    "a = 9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a8eefc84",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "# int() 转换类型 转换为整数\n",
    "b = int(11.5)\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "c538933f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "c = 5+3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "89770330",
   "metadata": {},
   "source": [
    "#### 课后练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2ab68d92",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "a = 1\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "21e9d2cf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "100.6 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "b = 100.6\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "629a728d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10086 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "a = 10086\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "f58c012f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.2 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "a = 0.2\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "628d1493",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "a = 2\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9dc9a84d",
   "metadata": {},
   "source": [
    "## 2.字符串(string)\n",
    ">> 2.1. 关于字符串的基本内容\n",
    ">> 2.2. 关于字符串的方法和函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9f3c0e50",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\" \n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "50d4f0ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = 'Alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "fc2b71bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = '''Alex'''\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "26b5be34",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sjjj\n"
     ]
    }
   ],
   "source": [
    "print(\"\"\"sjjj\"\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "fb7d76b1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "sss\n"
     ]
    }
   ],
   "source": [
    "print('''sss''')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cc021256",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 双引号里面可以包括单引号\n",
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3ca06203",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'nfdsjkf\"fdsnjlk'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 单引号里面也可以包括双引号\n",
    "'nfdsjkf\"fdsnjlk'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "22e12c62",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# \\ 用来转义\n",
    "'doesn\\'t'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "9de6bdbe",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 给网页HTML赋值：用三引号\n",
    "nfu_index_pages_html=\"\"\"\n",
    "<meta name=\"renderer\" content=\"webkit\">\n",
    "\t<!-- 强制360默认使用极速模式 -->\n",
    "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n",
    "\t<!-- 强制360默认使用极速模式 -->\n",
    "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n",
    "\t<title>广州南方学院</title>\n",
    "\t<meta&nbsp;name=”keywords”&nbsp;content=”南方学院,广州南方,本科,一流大学″>\n",
    "       <meta&nbsp;name=”description”&nbsp;content=”广州南方学院”>\n",
    "\n",
    "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/swiper-3.3.1.min.css\">\n",
    "\t<link href=\"css/lin.css\" rel=\"stylesheet\" type=\"text/css\">\n",
    "\n",
    "\t<script src=\"js/jquery-1.11.3.min.js\">\n",
    "\t</script>\n",
    "\t<script src=\"js/jquery-1.11.1.js\">\n",
    "\t</script>\n",
    "\t<script src=\"js/jquery.easie-min.js\" type=\"text/javascript\">\n",
    "\t</script>\n",
    "\t<script src=\"js/swiper.min.js\" type=\"text/javascript\">\n",
    "\t</script>\n",
    "\t<script src=\"js/lin.js\">\n",
    "\t</script>\n",
    "\t\n",
    "\t\n",
    "\t<link href=\"css/page.css\" rel=\"stylesheet\" type=\"text/css\">\n",
    "\t<link href=\"http://www.nfu.edu.cn/Public/favicon.ico\" rel=\"Shortcut Icon\">\n",
    "\t<link href=\"http://www.nfu.edu.cn/Public/favicon.ico\" rel=\"Bookmark\">\n",
    "\n",
    "\t<link rel=\"stylesheet\" href=\"css/jalendar.css\" type=\"text/css\">\n",
    "\t<script src=\"js/jquery.SuperSlide.2.1.js\" type=\"text/javascript\">\n",
    "\t</script>\n",
    "\t<script type=\"text/javascript\" src=\"js/jalendar.js\">\n",
    "\t</script>\n",
    "\t<!--<script type=\"text/javascript\">\n",
    "\t\tvar w=window.screen.width;\n",
    "\t\tif(w<=640){\n",
    "\t\t\tlocation.href=\"https://www.nfu.edu.cn/index.htm\";\n",
    "\t\t}\n",
    "\t\t$(function () {\n",
    "\t\t\t$('#myId').jalendar({\n",
    "\t\t\t\tcustomDay: '2020/4/07',\n",
    "\t\t\t\tcolor: '#ed145a',\n",
    "\t\t\t\tlang: 'EN'\n",
    "\t\t\t});\n",
    "\t\t});\n",
    "\t</script>-->\n",
    "\t<link rel=\"stylesheet\" href=\"css/orman.css\" type=\"text/css\" media=\"screen\">\n",
    "\t<link rel=\"stylesheet\" href=\"css/nivo-slider.css\" type=\"text/css\" media=\"screen\">\n",
    "\n",
    "\n",
    "\t&#xFEFF;<!--头部-->\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "e2a6d2db",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "<meta name=\"renderer\" content=\"webkit\">\n",
      "\t<!-- 强制360默认使用极速模式 -->\n",
      "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n",
      "\t<!-- 强制360默认使用极速模式 -->\n",
      "\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no\">\n",
      "\t<title>广州南方学院</title>\n",
      "\t<meta&nbsp;name=”keywords”&nbsp;content=”南方学院,广州南方,本科,一流大学″>\n",
      "       <meta&nbsp;name=”description”&nbsp;content=”广州南方学院”>\n",
      "\n",
      "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/swiper-3.3.1.min.css\">\n",
      "\t<link href=\"css/lin.css\" rel=\"stylesheet\" type=\"text/css\">\n",
      "\n",
      "\t<script src=\"js/jquery-1.11.3.min.js\">\n",
      "\t</script>\n",
      "\t<script src=\"js/jquery-1.11.1.js\">\n",
      "\t</script>\n",
      "\t<script src=\"js/jquery.easie-min.js\" type=\"text/javascript\">\n",
      "\t</script>\n",
      "\t<script src=\"js/swiper.min.js\" type=\"text/javascript\">\n",
      "\t</script>\n",
      "\t<script src=\"js/lin.js\">\n",
      "\t</script>\n",
      "\t\n",
      "\t\n",
      "\t<link href=\"css/page.css\" rel=\"stylesheet\" type=\"text/css\">\n",
      "\t<link href=\"http://www.nfu.edu.cn/Public/favicon.ico\" rel=\"Shortcut Icon\">\n",
      "\t<link href=\"http://www.nfu.edu.cn/Public/favicon.ico\" rel=\"Bookmark\">\n",
      "\n",
      "\t<link rel=\"stylesheet\" href=\"css/jalendar.css\" type=\"text/css\">\n",
      "\t<script src=\"js/jquery.SuperSlide.2.1.js\" type=\"text/javascript\">\n",
      "\t</script>\n",
      "\t<script type=\"text/javascript\" src=\"js/jalendar.js\">\n",
      "\t</script>\n",
      "\t<!--<script type=\"text/javascript\">\n",
      "\t\tvar w=window.screen.width;\n",
      "\t\tif(w<=640){\n",
      "\t\t\tlocation.href=\"https://www.nfu.edu.cn/index.htm\";\n",
      "\t\t}\n",
      "\t\t$(function () {\n",
      "\t\t\t$('#myId').jalendar({\n",
      "\t\t\t\tcustomDay: '2020/4/07',\n",
      "\t\t\t\tcolor: '#ed145a',\n",
      "\t\t\t\tlang: 'EN'\n",
      "\t\t\t});\n",
      "\t\t});\n",
      "\t</script>-->\n",
      "\t<link rel=\"stylesheet\" href=\"css/orman.css\" type=\"text/css\" media=\"screen\">\n",
      "\t<link rel=\"stylesheet\" href=\"css/nivo-slider.css\" type=\"text/css\" media=\"screen\">\n",
      "\n",
      "\n",
      "\t&#xFEFF;<!--头部-->\n"
     ]
    }
   ],
   "source": [
    "print(nfu_index_pages_html)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12a064a0",
   "metadata": {},
   "source": [
    "#### 练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "7a98b1f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "title = \"curry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2b948f4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "curry <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(title,type(title))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "dbda1a06",
   "metadata": {},
   "outputs": [],
   "source": [
    "title = \"curry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "21964e2a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "curry <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(title,type(title))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b12125b4",
   "metadata": {},
   "source": [
    "## 2 [关于字符串的方法及函数](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)\n",
    "\n",
    "> 1. 字符串的定义\n",
    ">> 1. Single quotes: 'allows embedded \"double\" quotes'\n",
    ">> 2. Double quotes: \"allows embedded 'single' quotes\"\n",
    ">> 3. Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\"\n",
    "> 2. in 检查成员对象\n",
    "> 3. 字符串的拼接\n",
    "> 4. 字符串的方法\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "63b7be86",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考 如何判断一段文本中是否存在\"广州”，例如 文本 title中的内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6bcf3b8e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化区温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 索引值index  看不到  0-18：广州南方学院坐落于广州市从化区温泉镇   有多少个字符就有多少个索引值\n",
    "title = \"广州南方学院坐落于广州市从化区温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "783ace87",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'坐'"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "be8c7c1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'区'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[14]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "cb6e7a72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "dc64be46",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "918b42b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'院'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "91b35d4d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检查文本的总长度\n",
    "len(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "e86d6bd7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "edb5d91c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'泉'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "fa6db646",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取一定范围的值，这种方法我们称其为“切片”\n",
    "title[0:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "7dd36f91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "aa01a94a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'方学院坐落'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[3:8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "ec9942f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'于广州市从化区温泉镇'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[8:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7081f8b1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南方'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d7f2125b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"从化\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "ec7c33f0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"温泉\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d131d1fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "9f2ec279",
   "metadata": {},
   "outputs": [],
   "source": [
    "## enumerate 枚举，既可以获取到内容 item ，又可以获取到  索引值 index。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "0238d51f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 区\n",
      "15 温\n",
      "16 泉\n",
      "17 镇\n"
     ]
    }
   ],
   "source": [
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "192a9db8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 区\n",
      "15 温\n",
      "16 泉\n",
      "17 镇\n"
     ]
    }
   ],
   "source": [
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d8c7c472",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"只因你太美\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "dffb4ee7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 只\n",
      "1 因\n",
      "2 你\n",
      "3 太\n",
      "4 美\n"
     ]
    }
   ],
   "source": [
    "for i,r in enumerate(name):\n",
    "    print(i,r)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "147e41e4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考，如何判断一段文本中是否存在“广州”，例如文本  title  中的内容,还可以确定其出现的次数 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "d9fc33b4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "广州这个词在这段文字中\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "广州这个词在这段文字中\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 区\n",
      "15 温\n",
      "16 泉\n",
      "17 镇\n"
     ]
    }
   ],
   "source": [
    "# 方法1\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)\n",
    "    if j == \"广\":\n",
    "         if title[i+1] == \"州\":\n",
    "                print(\"广州这个词在这段文字中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "304d454f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#方法二\n",
    "title.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c66f543c",
   "metadata": {},
   "source": [
    "#### page59 in 检查成员对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "3419575b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "1f57379e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"深圳\" in title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "f8c50c83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"温泉\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04e3a002",
   "metadata": {},
   "source": [
    "### 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "4c0957e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好,Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好\" + \",\"+ \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "8bd9e8a9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "acab\n"
     ]
    }
   ],
   "source": [
    "print(\"a\"+\"c\"+\"a\"+\"b\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "ca6efd89",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"int\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [43]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以和数字连接\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m你好\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m2\u001b[39;49m)\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
     ]
    }
   ],
   "source": [
    "# 字符串不可以和数字连接\n",
    "print(\"你好\"+ 2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "c97d53bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好5\n"
     ]
    }
   ],
   "source": [
    "# 但是字符串里的数字可以   \"5\"这样也是属于字符串\n",
    "print(\"你好\"+\"5\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "3e01e21b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "902b20f8",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [45]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 字符串不可以用来运算\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "# 字符串不可以用来运算\n",
    "\"3\"/\"2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "363230a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 字符串和数字导致的笑话\n",
    "width=\"10\" \n",
    "heigt=8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "5bfcb45d",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积=width * heigt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "8c55f738",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'1010101010101010'"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "768cfaa9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 正确做法\n",
    "width = 10\n",
    "heigt = 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "605d8014",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * heigt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "cc03a54b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "80"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0dbc6c5e",
   "metadata": {},
   "source": [
    "### 字符串的方法\n",
    "#### 1.str.capitalize():可以将字母转成大写\n",
    "#### 2.str.count():数量\n",
    "#### 3.str.split()：去除内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "f218b259",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "04e3c9dd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "25f0ff72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "b21e1098",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院坐落于广州市从化区温泉镇'"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "0f58445a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "3efa5d1d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "5853fac4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院', '广州市从化区温泉镇']"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "198268c2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
